# 这个脚本没什么用

import json

filenames = []
anns = []
num_label = 0
num_chars = 0


for line in open("D:\myAPPData\wechat\WeChat Files\wxid_xx3dgcn25fxo22\FileStorage\File/2022-09\缅甸语\缅甸语/Label.txt", "r", encoding='utf-8'):
    strs = line.split("\t")
    filename = "藏语修订版20220915/" + strs[0]
    filenames.append(filename)
    anns.append(json.loads(strs[1]))

ftxt = open("./text.txt","w",encoding="utf-8")
sample_metrics = []
class_labels = []
for i in range(len(filenames)):
    print(i * 100 / len(filenames))
    # 第i个文件
    label = anns[i]
    # 文本行检测
    label_chars = []
    labe_char_boxes = []

    class_label = []
    class_pre = []
    class_pre_boxs = []
    class_label_boxs = []
    #label
    for j in range(len(label)):
        value = label[j]["transcription"]
        # if value == 'picture':
        if 'picture' in value:
            class_label.append(0)
            xyxy = label[j]["points"]
            class_label_boxs.append(xyxy)
        elif 'paragraph' in value:
            class_label.append(1)
            xyxy = label[j]["points"]
            class_label_boxs.append(xyxy)

        elif 'table' in value:
            class_label.append(2)
            xyxy = label[j]["points"]
            class_label_boxs.append(xyxy)

        elif value.split("-")[0] == 'cell':
            class_label.append(3)
            xyxy = label[j]["points"]
            class_label_boxs.append(xyxy)
        else:
            label_chars.append(value)
            ftxt.write(value + "\n")
            # xyxy = label[j]["points"][0] + label[j]["points"][2]
            xyxy = label[j]["points"]
            labe_char_boxes.append(xyxy)
a =100